package cn.yili12.server.info.handler;

import cn.yili12.server.cache.OnlineUserCache;
import cn.yili12.server.client.handler.BaseClientHandler;
import cn.yili12.server.client.vo.ClientMessage;
import cn.yili12.server.info.vo.InfoMessage;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class OfflineInfoHandler extends BaseInfoHandler {

    @Autowired
    protected OnlineUserCache onlineUserCache;

    @Override
    public boolean handler(InfoMessage message) {
        //通知所有人  我下线了
        webSocketChannelPool.broadcast(message.getFrom(), JSON.toJSONString(message));
        onlineUserCache.remove(message.getFrom());
        return true;
    }
}
